package com.sunny.ynhz.model;

import android.content.Context;
import android.util.Log;

import com.sunny.ynhz.api.HttpManager;
import com.sunny.ynhz.api.subscriber.ApiSubscriber;
import com.sunny.ynhz.bean.MoreLineProBlemBean;
import com.sunny.ynhz.bean.ProblemStaticBean;
import com.sunny.ynhz.bean.RingBean;
import com.sunny.ynhz.utils.SPUtil;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by huhuan123 on 2018/8/10.
 *
 * @describe TODO
 */

public class ProblemStaticModel {
    Context context;
    IProblemTypeNewResultView iProblemTypeResultView;

    public ProblemStaticModel(Context context, IProblemTypeNewResultView iProblemTypeResultView) {
        this.context = context;
        this.iProblemTypeResultView = iProblemTypeResultView;
    }

    public void getInstanceMsgList(String startTime, String endTime) {
        Observable<ProblemStaticBean> problemStaticBeanObservable = HttpManager.getInstance().getCurrentStaticProblen(startTime, endTime, SPUtil.get("userId", "").toString()).subscribeOn(Schedulers.io());
        Observable<MoreLineProBlemBean> moreLineProBlemBeanObservable = HttpManager.getInstance().getMoreLineProblem(SPUtil.get("userId", "").toString(), "").subscribeOn(Schedulers.io());
        Observable<RingBean> ringBeanObservable = HttpManager.getInstance().getCurrentStaticProblenSandType(startTime, endTime, SPUtil.get("userId", "").toString()).subscribeOn(Schedulers.io());
        Observable.mergeDelayError(problemStaticBeanObservable, moreLineProBlemBeanObservable, ringBeanObservable).observeOn(AndroidSchedulers.mainThread()).subscribe(new ApiSubscriber(context, new ApiSubscriber.HttpOnResultListener<Object>() {
            @Override
            public void onNext(Object o) {
                iProblemTypeResultView.onSuccess(o);
            }

            @Override
            public void onCompleted() {
                iProblemTypeResultView.onCompleted();
            }

            @Override
            public void onstart() {
                iProblemTypeResultView.onStartLoad();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                iProblemTypeResultView.onFail();
            }
        }));

    }

    public void getMorenLineBJ(String startTime, String endTime) {
        Observable<ProblemStaticBean> problemStaticBeanObservable = HttpManager.getInstance().getCurrentStaticProblen(startTime, endTime, SPUtil.get("userId", "").toString()).subscribeOn(Schedulers.io());
        Observable<RingBean> ringBeanObservable = HttpManager.getInstance().getCurrentStaticProblenSandType(startTime, endTime, SPUtil.get("userId", "").toString()).subscribeOn(Schedulers.io());
        Observable.mergeDelayError(problemStaticBeanObservable, ringBeanObservable).observeOn(AndroidSchedulers.mainThread()).subscribe(new ApiSubscriber(context, new ApiSubscriber.HttpOnResultListener<Object>() {
            @Override
            public void onNext(Object o) {
                iProblemTypeResultView.onSuccess(o);

            }

            @Override
            public void onCompleted() {

            }

            @Override
            public void onstart() {
                iProblemTypeResultView.onStartLoad();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                iProblemTypeResultView.onFail();
            }
        }));

    }


}
